package ru.paswd.marketprice.geocoder.sputnik;

import feign.Feign;
import feign.Logger;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import org.springframework.beans.factory.FactoryBean;

public class SputnikClientFactoryBean implements FactoryBean<SputnikClient> {
    @Override
    public SputnikClient getObject() {
        return Feign.builder()
                .client(new OkHttpClient())
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder())
                .logger(new Slf4jLogger())
                .logLevel(Logger.Level.BASIC)
                .target(SputnikClient.class, "http://search.maps.sputnik.ru");
    }

    @Override
    public Class<?> getObjectType() {
        return SputnikClient.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
